from PyQt5.Qt import *
import sys



class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(600,400)
        self.setFixedWidth(300)
        self.data=[
            {'name': '袁隆平','id':1},
            {'name': '孙中山', 'id': 2},
            {'name': '刘秀', 'id': 3},
            {'name': '李世民', 'id': 4},
            {'name': '秦始皇', 'id': 5}
            ]
        self.addLabels()
        self.set1Style()

    # itemclick = pyqtSignal([object])
    def addLabel(self,it,layout):
        lb = QPushButton()
        lb.setText(it['name'])
        lb.setProperty('name', 'lb')
        lb.setFixedHeight(64)
        lb.setProperty('data', it)
        lb.clicked.connect(lambda: self.itemClick(lb.property('data')))
        layout.addWidget(lb)


    def addLabels(self):
        layout = QVBoxLayout()
        layout.setSpacing(0)
        self.setLayout(layout)

        data = self.data
        for it in data:
            self.addLabel(it,layout)


        lb = QLabel()
        layout.addWidget(lb)

    def set1Style(self):
        self.setStyleSheet("""
        QPushButton[name="lb"]{
            background-color:#eae7e5;
            border:1px solid #666666;
            border-top:0px;
            padding-left:40px;
            font-size:24px;
            text-align:left;
        }
        QPushButton[name="lb"]:hover{
        background-color:yellow;       
        
        }
        QPushButton[name="lb"]:pressed{
        background-color:yellow;       
        
        }
        """)
    def itemClick(self,e):
        print('1231')
        print(e)


if __name__=='__main__':
    app = QApplication(sys.argv)
    w = Window()
    w.show()
    sys.exit(app.exec_())